﻿Imports System.Collections.ObjectModel
Public Class Interleaved2to5
    Implements IBarCode

    Private _code As String

    Public Sub New(code As String)
        _code = code
    End Sub

    Public Property Code As String Implements IBarCode.Code
        Get
            Return _code
        End Get
        Set(value As String)
            _code = value
        End Set
    End Property

    Public ReadOnly Property BinaryCode As System.Collections.ObjectModel.Collection(Of BarCodeStroke) Implements IBarCode.BinaryCode
        Get
            Dim black As System.Windows.Media.Color = System.Windows.Media.Color.FromRgb(0, 0, 0)
            Dim white As System.Windows.Media.Color = System.Windows.Media.Color.FromRgb(255, 255, 255)
            Dim output As New Collection(Of BarCodeStroke)
            output.Add(New BarCodeStroke(black)) : output.Add(New BarCodeStroke(white)) : output.Add(New BarCodeStroke(black)) : output.Add(New BarCodeStroke(white))

            Dim c0 As New Collection(Of BarCodeStroke) : c0.Add(New BarCodeStroke(False)) : c0.Add(New BarCodeStroke(False)) : c0.Add(New BarCodeStroke(True)) : c0.Add(New BarCodeStroke(True)) : c0.Add(New BarCodeStroke(False))
            Dim c1 As New Collection(Of BarCodeStroke) : c1.Add(New BarCodeStroke(True)) : c1.Add(New BarCodeStroke(False)) : c1.Add(New BarCodeStroke(False)) : c1.Add(New BarCodeStroke(False)) : c1.Add(New BarCodeStroke(True))
            Dim c2 As New Collection(Of BarCodeStroke) : c2.Add(New BarCodeStroke(False)) : c2.Add(New BarCodeStroke(True)) : c2.Add(New BarCodeStroke(False)) : c2.Add(New BarCodeStroke(False)) : c2.Add(New BarCodeStroke(True))
            Dim c3 As New Collection(Of BarCodeStroke) : c3.Add(New BarCodeStroke(True)) : c3.Add(New BarCodeStroke(True)) : c3.Add(New BarCodeStroke(False)) : c3.Add(New BarCodeStroke(False)) : c3.Add(New BarCodeStroke(False))
            Dim c4 As New Collection(Of BarCodeStroke) : c4.Add(New BarCodeStroke(False)) : c4.Add(New BarCodeStroke(False)) : c4.Add(New BarCodeStroke(True)) : c4.Add(New BarCodeStroke(False)) : c4.Add(New BarCodeStroke(True))
            Dim c5 As New Collection(Of BarCodeStroke) : c5.Add(New BarCodeStroke(True)) : c5.Add(New BarCodeStroke(False)) : c5.Add(New BarCodeStroke(True)) : c5.Add(New BarCodeStroke(False)) : c5.Add(New BarCodeStroke(False))
            Dim c6 As New Collection(Of BarCodeStroke) : c6.Add(New BarCodeStroke(False)) : c6.Add(New BarCodeStroke(True)) : c6.Add(New BarCodeStroke(True)) : c6.Add(New BarCodeStroke(False)) : c6.Add(New BarCodeStroke(False))
            Dim c7 As New Collection(Of BarCodeStroke) : c7.Add(New BarCodeStroke(False)) : c7.Add(New BarCodeStroke(False)) : c7.Add(New BarCodeStroke(False)) : c7.Add(New BarCodeStroke(True)) : c7.Add(New BarCodeStroke(True))
            Dim c8 As New Collection(Of BarCodeStroke) : c8.Add(New BarCodeStroke(True)) : c8.Add(New BarCodeStroke(False)) : c8.Add(New BarCodeStroke(False)) : c8.Add(New BarCodeStroke(True)) : c8.Add(New BarCodeStroke(False))
            Dim c9 As New Collection(Of BarCodeStroke) : c9.Add(New BarCodeStroke(False)) : c9.Add(New BarCodeStroke(True)) : c9.Add(New BarCodeStroke(False)) : c9.Add(New BarCodeStroke(True)) : c9.Add(New BarCodeStroke(False))
            For index As Integer = 1 To Code.Length Step 2
                Dim v1 As String = Mid(Code, index, 1)
                Dim v2 As String = Mid(Code, index + 1, 1)
                Dim cv1, cv2 As Collection(Of BarCodeStroke)
                Select Case v1
                    Case "0"
                        cv1 = c0
                    Case "1"
                        cv1 = c1
                    Case "2"
                        cv1 = c2
                    Case "3"
                        cv1 = c3
                    Case "4"
                        cv1 = c4
                    Case "5"
                        cv1 = c5
                    Case "6"
                        cv1 = c6
                    Case "7"
                        cv1 = c7
                    Case "8"
                        cv1 = c8
                    Case "9"
                        cv1 = c9
                End Select
                Select Case v2
                    Case "0"
                        cv2 = c0
                    Case "1"
                        cv2 = c1
                    Case "2"
                        cv2 = c2
                    Case "3"
                        cv2 = c3
                    Case "4"
                        cv2 = c4
                    Case "5"
                        cv2 = c5
                    Case "6"
                        cv2 = c6
                    Case "7"
                        cv2 = c7
                    Case "8"
                        cv2 = c8
                    Case "9"
                        cv2 = c9
                End Select
                For i As Integer = 0 To 4
                    If cv1(i).IsDoubleWidth Then
                        output.Add(New BarCodeStroke(black))
                        output.Add(New BarCodeStroke(black))
                    Else
                        output.Add(New BarCodeStroke(black))
                    End If
                    If cv2(i).IsDoubleWidth Then
                        output.Add(New BarCodeStroke(white))
                        output.Add(New BarCodeStroke(white))
                    Else
                        output.Add(New BarCodeStroke(white))
                    End If
                Next
            Next
            output.Add(New BarCodeStroke(black)) : output.Add(New BarCodeStroke(black)) : output.Add(New BarCodeStroke(white)) : output.Add(New BarCodeStroke(black))
            Return output
        End Get
    End Property
End Class
